//返回的是用户唯一的临时标识 uuid
//用户一旦有了唯一标识，不会轻易改变的 localStorage
import { v4 as uuidv4 } from 'uuid';

export const getUserTempId = () => {
  let userTempId = localStorage.getItem('USERTEMPID_KEY')

  if(!userTempId){
    //创建新的userTempId
    userTempId = uuidv4(); // ⇨ '9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d'
    //再存储到localStorage内部，保证下一次拿的时候可以获取到
    localStorage.setItem('USERTEMPID_KEY',userTempId)
  }
  return userTempId
}